﻿using System;
using LuaInterface;

public class TestClassWrap
{
	public static void Register(IntPtr L)
	{
		LuaMethod[] regs = new LuaMethod[]
		{
			new LuaMethod("Create", Create),
			new LuaMethod("PrintTest", PrintTest),
			new LuaMethod("New", _CreateTestClass),
			new LuaMethod("GetClassType", GetClassType),
		};

		LuaField[] fields = new LuaField[]
		{
		};

		LuaScriptMgr.RegisterLib(L, "TestClass", typeof(TestClass), regs, fields, typeof(object));
	}

	[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
	static int _CreateTestClass(IntPtr L)
	{
		int count = LuaDLL.lua_gettop(L);

		if (count == 0)
		{
			TestClass obj = new TestClass();
			LuaScriptMgr.PushObject(L, obj);
			return 1;
		}
		else
		{
			LuaDLL.luaL_error(L, "invalid arguments to method: TestClass.New");
		}

		return 0;
	}

	static Type classType = typeof(TestClass);

	[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
	static int GetClassType(IntPtr L)
	{
		LuaScriptMgr.Push(L, classType);
		return 1;
	}

	[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
	static int Create(IntPtr L)
	{
		LuaScriptMgr.CheckArgsCount(L, 0);
		TestClass o = TestClass.Create();
		LuaScriptMgr.PushObject(L, o);
		return 1;
	}

	[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
	static int PrintTest(IntPtr L)
	{
		LuaScriptMgr.CheckArgsCount(L, 1);
		TestClass obj = (TestClass)LuaScriptMgr.GetNetObjectSelf(L, 1, "TestClass");
		obj.PrintTest();
		return 0;
	}
}

